#include <time.h>

#include "GRASP.h"
#include "Kruskal.h"
#include "FileSTS.h"

#define NUM_ITER 120

double startwtime = 0.0, endwtime;
int melhorIter = 0;
clock_t tInicio, tFim, tDecorrido;

int main(int argc, char** argv){
	if(argc == 4){
	
		srand(time(NULL));
		
		//Inicializando os dados de arquivo
		Solucao::loadEntrada(argv[1]);
		double alpha = atof(argv[2]);
		GRASP g(Solucao::tamanho, alpha);
		
		tInicio = clock();

		SolucaoGRASPSTS *sbest = NULL;
		for(int i=0; i<NUM_ITER; i++){
			//Fase de Construcao e Busca Local.
			SolucaoGRASPSTS *sol = g.construcao();
			SolucaoGRASPSTS *sbl = g.descida(sol);
			delete sol;
			//Executando o VNS.
			SolucaoGRASPSTS *svns = g.ILS(sbl);
			
			if(sbest == NULL){
				sbest = svns;
				melhorIter = i;
			}else{
				if(svns->avaliacao < sbest->avaliacao){
					delete sbest;
					sbest = svns;
					melhorIter = i;
				}else
					delete svns;
			}
		}
	
		tFim = clock();
		tDecorrido = (tFim - tInicio) / (CLOCKS_PER_SEC / 1000);
		FileSTS::printInstancia(argv[3], 1, alpha, sbest->tamanho, sbest->numClient, melhorIter, sbest->avaliacao, (int)tDecorrido);
		printf("Final: %s F: %f Tempo: %f\n", sbest->print(), sbest->avaliacao, (double)tDecorrido);
		
	}else{
		puts("<usage: grasp nameFile alpha estrategia>");
	}
	return 0;
}

